/*
    Base Class Of WebPage
*/
import Log, { logtypedef } from "../common/RunLog";
import Func from "../middleware/CommonFunc";
import WebFunc from "../middleware/WebCommon";

export default class WebPageBase{
    public constructor(){

    }
    protected _showErrorLog(msg:string){ 
        Log.addlog(msg, logtypedef.LOG_TYPE_EXCEPTION);
    }

    protected _showDebugLog(msg:string){ 
        Log.output(msg);
    }

    protected _parseParam(res:any, paramObj:any):any{
        if(typeof(paramObj) == "string"){
            paramObj = JSON.parse(paramObj);
        }
        var param = WebFunc.checkParam(paramObj);
        return param;
    }
    protected _clientIP(req:any):string{
        return Func.getClientIp(req);
    }

    protected _getErrorJson(code:number,msg:string) : {[key:string]:string}{
        return {"result":"FAILED","code":code+"", "msg":msg};
    }

    public sendError(res:any, error:string) {
        res.json({"result":"FAILED","msg":error});
    }
    protected outputRoomError(res:any, error:string) {
        res.json({"result":"FAILED","msg":error});
    }
}